package com.ruoyi.web.controller.system;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.FunctionTable;
import com.ruoyi.system.service.IFunctionTableService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 功能Controller
 * 
 * @author ruoyi
 * @date 2024-12-02
 */
@RestController
@RequestMapping("/system/table")
public class FunctionTableController extends BaseController
{
    @Autowired
    private IFunctionTableService functionTableService;

    /**
     * 查询功能列表
     */
    @PreAuthorize("@ss.hasPermi('system:table:list')")
    @GetMapping("/list")
    public TableDataInfo list(FunctionTable functionTable)
    {
        startPage();
        List<FunctionTable> list = functionTableService.selectFunctionTableList(functionTable);
        return getDataTable(list);
    }

    /**
     * 导出功能列表
     */
    @PreAuthorize("@ss.hasPermi('system:table:export')")
    @Log(title = "功能", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FunctionTable functionTable)
    {
        List<FunctionTable> list = functionTableService.selectFunctionTableList(functionTable);
        ExcelUtil<FunctionTable> util = new ExcelUtil<FunctionTable>(FunctionTable.class);
        util.exportExcel(response, list, "功能数据");
    }

    /**
     * 获取功能详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:table:query')")
    @GetMapping(value = "/{functionId}")
    public AjaxResult getInfo(@PathVariable("functionId") Long functionId)
    {
        return success(functionTableService.selectFunctionTableByFunctionId(functionId));
    }

    /**
     * 新增功能
     */
    @PreAuthorize("@ss.hasPermi('system:table:add')")
    @Log(title = "功能", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FunctionTable functionTable)
    {
        return toAjax(functionTableService.insertFunctionTable(functionTable));
    }

    /**
     * 修改功能
     */
    @PreAuthorize("@ss.hasPermi('system:table:edit')")
    @Log(title = "功能", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FunctionTable functionTable)
    {
        return toAjax(functionTableService.updateFunctionTable(functionTable));
    }

    /**
     * 删除功能
     */
    @PreAuthorize("@ss.hasPermi('system:table:remove')")
    @Log(title = "功能", businessType = BusinessType.DELETE)
	@DeleteMapping("/{functionIds}")
    public AjaxResult remove(@PathVariable Long[] functionIds)
    {
        return toAjax(functionTableService.deleteFunctionTableByFunctionIds(functionIds));
    }
}
